﻿using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;

namespace YJKRoomInspection.Model
{
	public class AdapteRoomResulePacker
	{
		public string AddRoomType
		{
			get
			{
				return this.addRoomType;
			}
			set
			{
				this.addRoomType = value;
			}
		}

		public FrontRoomPacker FrontRoomPacker
		{
			get
			{
				return this.frontRoomPacker;
			}
			set
			{
				this.frontRoomPacker = value;
			}
		}

		public Room AddRoom
		{
			get
			{
				return this.addRoom;
			}
			set
			{
				this.addRoom = value;
			}
		}

		public FilledRegion AddFilledRegion
		{
			get
			{
				return this.addFilledRegion;
			}
			set
			{
				this.addFilledRegion = value;
			}
		}

		public double RegionZVal
		{
			get
			{
				return this.regionZVal;
			}
			set
			{
				this.regionZVal = value;
			}
		}

		public Level UseLevel
		{
			get
			{
				return this.useLevel;
			}
			set
			{
				this.useLevel = value;
			}
		}

		public override bool Equals(object obj)
		{
			if (obj is AdapteRoomResulePacker && !(obj as AdapteRoomResulePacker).IfOnlyLevel())
			{
				return this.GetElementId() == (obj as AdapteRoomResulePacker).GetElementId() || base.Equals(obj);
			}
			return base.Equals(obj);
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		public bool IfOnlyLevel()
		{
			return this.FrontRoomPacker == null && this.AddRoom == null && this.AddFilledRegion == null;
		}

		public int GetElementId()
		{
			int result = -1;
			if (this.AddFilledRegion != null || this.FrontRoomPacker != null || this.AddRoom != null)
			{
				if (this.FrontRoomPacker != null)
				{
					result = this.FrontRoomPacker.ElementId;
				}
				else if (this.AddRoom != null)
				{
					result = this.AddRoom.Id.IntegerValue;
				}
				else
				{
					result = this.addFilledRegion.Id.IntegerValue;
				}
			}
			return result;
		}

		public Element GetElement()
		{
			Element result = null;
			if (this.AddFilledRegion != null || this.FrontRoomPacker != null || this.AddRoom != null)
			{
				if (this.FrontRoomPacker != null)
				{
					result = this.FrontRoomPacker.ThisRoom;
				}
				else if (this.AddRoom != null)
				{
					result = this.AddRoom;
				}
				else
				{
					result = this.addFilledRegion;
				}
			}
			return result;
		}

		public string GetElementDes()
		{
			string result = string.Empty;
			if (this.AddFilledRegion != null || this.FrontRoomPacker != null || this.AddRoom != null)
			{
				if (this.FrontRoomPacker != null)
				{
					result = this.GetABaseDes(this.FrontRoomPacker.ThisRoom.Name);
				}
				else if (this.AddRoom != null)
				{
					result = this.GetABaseDes(this.AddRoom.Name);
				}
				else
				{
					result = this.GetABaseDes(string.Empty);
				}
			}
			return result;
		}

		private string GetABaseDes(string strName)
		{
			string result = string.Empty;
			if (strName.Contains("特殊合用前室"))
			{
				result = string.Format("{0}", strName);
			}
			else if (strName.Contains("合用前室"))
			{
				result = string.Format("{0}", strName);
			}
			else if (strName.Contains("前室"))
			{
				result = string.Format("{0}", strName);
			}
			else
			{
				result = string.Format("{0}({1})", strName, this.AddRoomType);
			}
			return result;
		}

		private string addRoomType;

		private FrontRoomPacker frontRoomPacker;

		private Room addRoom;

		private FilledRegion addFilledRegion;

		private double regionZVal;

		private Level useLevel;
	}
}
